// pages/myPointsRecord/吗、ypoints record.js
var that,
  api = new (require('../../utils/api.js')),
  headimg = api.getimgurl(),
  app = getApp(),
  util = new (require('../../utils/util.js'));
Page({

  /**
   * 页面的初始数据
   */
  data: {
    integralList:[],
    nextPage:0,
    page:1,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    that=this;
    if (app.logininfo) {
      that.getscorerecord()
    } else {
      util.setwatcher(app, this.afterlogin)
    }
  },
  afterlogin: {
    logininfo: res => {
      that.getscorerecord()
    }
  },
    //积分记录列表
    getscorerecord(){
      wx.showLoading({
        title: '加载中',
      })
      let {page,integralList}=that.data
      api.scorerecord({page,cateId:0},res=>{
        wx.hideLoading()
        if(res.data.code==0){
          let {infoArr,nextPage}=res.data.entity.data
          if(infoArr.length>0){
            infoArr.forEach(x=>{
              x.date=util.formatDate(new Date(x.addTime*1000))
              integralList.push(x)
            })
          }
          that.setData({integralList,nextPage})
        }
      })
    },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    let {page,nextPage}=that.data
    if(nextPage==1){
      page=page+1
      that.setData({page},()=>{
        that.getscorerecord()
      })
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})